package com.ruyuan.payment.server.service;

import com.ruyuan.payment.server.domain.OrderSnapshot;
import com.ruyuan.payment.server.domain.OrderSnapshotExample;
import com.ruyuan.payment.server.mapper.OrderSnapshotMapper;
import com.ruyuan.payment.server.resp.OrderSnapshotQueryResp;
import com.ruyuan.payment.server.util.CopyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderSnapshotService {

    private static final Logger LOG = LoggerFactory.getLogger(OrderSnapshotService.class);

    @Resource
    private OrderSnapshotMapper orderSnapshotMapper;

    public OrderSnapshotQueryResp queryOne(String orderNo, Long memberId) {
        OrderSnapshotExample example = new OrderSnapshotExample();
        OrderSnapshotExample.Criteria criteria = example.createCriteria();
        criteria.andOrderNoEqualTo(orderNo);
        if (!ObjectUtils.isEmpty(memberId)) {
            criteria.andMemberIdEqualTo(memberId);
        }
        List<OrderSnapshot> list = orderSnapshotMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        } else {
            return CopyUtil.copy(list.get(0), OrderSnapshotQueryResp.class);
        }
    }
}
